package model{
	import assets.Card;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	public class AppModel extends EventDispatcher{
		private static var instance:AppModel;
		
		//dispatchevents
		public static const SHUFFLED_KAARTEN:String = "shuffled_kaarten";
		public static const DELETE_INTRO:String = "delete_intro";
		public static const DRAAI_USERS:String = "draai_users";
		public static const CURRENTCARD_CHANGED:String = "currentCard_changed";
		
		//public vars
		public var namesArr:Array = [];
		public var kaartenArr:Array = [];
		public var kaartenPiramideArr:Array =[];
		public var rijCount:Number;
		
		//getters & setters
		private var _clickedCard:Object;
		
		//standaard functies
		public function AppModel(e:Enforcer){
			if(e == null){
				throw new Error("AppModel is een Singleton");
			}
		}
		
		public static function getInstance():AppModel{
			if(instance == null){
				instance = new AppModel(new Enforcer());
			}
			return instance;
		}
		
		// Public Functions
		public function pushKaartenArr(kaart:String):void{
			this.kaartenArr.push(kaart);
		}
		
		public function deleteIntro():void{
			dispatchEvent(new Event(DELETE_INTRO));
		}
		
		public function controleCards():void{
			for(var i:uint=0; i < 5; i++){
				//if(clickedCard.tur 
			}
		}
		
		//getters & setters
		public function get clickedCard():Object
		{
			return _clickedCard;
		}
		
		public function set clickedCard(value:Object):void
		{
			if(clickedCard != value){
				_clickedCard = value;
				trace("[appModel] currentCard: "+clickedCard.turnd);
				dispatchEvent(new Event(CURRENTCARD_CHANGED));
			}
		}
		
		//schuffle de array met symbolen
		public function shuffleArray(arr:Array):Array{
			var arr2:Array = [];
			while (arr.length > 0){
				arr2.push(arr.splice(Math.round(Math.random() * (arr.length - 1)), 1)[0]);
			}
			return arr2;
		}
		
		//genereer een random number
		public function random(min:Number, max:Number):Number{
			return Math.round(min + Math.random() * (max - min));
		}
		
		//een array leggmaken
		public function  clearArray(array:Array):void{
			array.splice(0,array.length);
		}
	}
}

internal class Enforcer{
	
}